﻿using FastEndpoints;
using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;
using vite_net.Common;
using vite_net.Controllers.WorkFlow;

namespace vite_net.Controllers
{
    public abstract class ViteNetEndpoint<TRequest, TResponse> : Endpoint<TRequest, TResponse> where TRequest : notnull
    {
        //[DontInject] 可以属性注入
        //public HttpContext HttpContext { get; internal set; }

        protected long GetCurrentUserId()
        {
            return long.TryParse(User.FindFirst("UserId")?.Value, out long outId) ? outId : 0; 
        }

        protected string GetCurrentUsername()
        {
            return User.FindFirst("UserName")?.Value ?? string.Empty;
        }
    }

    public abstract class ViteNetEndpoint<TRequest, TResponse, TMapper> : Endpoint<TRequest, TResponse, TMapper> where TRequest : notnull where TResponse : notnull where TMapper : class, IMapper
    {
        protected string GetCurrentUserId()
        {
            return User.FindFirst("UserId")?.Value ?? string.Empty;
        }

        protected string GetCurrentUsername()
        {
            return User.FindFirst("UserName")?.Value ?? string.Empty;
        }
    }
}
